import { DailyRule } from "../../../rules/DailyRule";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { ParamsConst } from "../../../../common/global/ParamsConst";
import { BrowerUtil } from "../../../../../com/gengine/utils/BrowerUtil";
import { Cache } from "../../../cache/Cache";
import { Tooltip } from "../../common/tooltip/Tooltip";
import { ObjCreate } from "../../common/ObjCreate";
import { LayerManager } from "../../../manager/LayerManager";
import { Global } from "../../../../../com/gengine/global/Global";
import { GiftInfo } from "../../../model/GiftInfo";
import { ItemConfig } from "../../../resource/ItemConfig";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { ColorConfig } from "../../../resource/ColorConfig";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { LoaderManager } from "../../../../../com/gengine/resource/LoaderManager";
import { Language } from "../../../../../extend/language/Language";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { GTextArea } from "../../../../../com/mui/controls/GTextArea";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImageInfo } from "../../../../../com/gengine/resource/info/ImageInfo";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
type int = number;
//class GiftItem
    
    export  class GiftItem /* flash.display.Sprite */
    {
        constructor(arg1: Boolean=false)
        {
            
            this.initUI(arg1);
            addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStage);
            addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStage);
            return;
        }

        /* internal  */onOpt1BtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._info) 
            {
                var loc1=this._info.code;
                switch (loc1) 
                {
                    case DailyRule.GiftNovicePack1:
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.NovicePackGet, 2));
                        break;
                    }
                    case DailyRule.GiftNovicePack2:
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.NoviceCardOpen));
                        break;
                    }
                    case DailyRule.GiftNovicePack3:
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.NovicePackGet, 3));
                        break;
                    }
                    case DailyRule.GiftPhonePack:
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.NoviceCardOpen, ParamsConst.instance.phoneUrl));
                        break;
                    }
                    case DailyRule.GiftMall360Pack1: case DailyRule.GiftMall360Pack2:
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.NoviceCardOpen, this._info.code.toString()));
                        break;
                    }
                    case DailyRule.Gift91WanPack:
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.NoviceCardOpen, ParamsConst.instance.Gift91Wan));
                        break;
                    }
                    case DailyRule.Gift360PetPack:
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.NoviceCardOpen, this._info.code.toString()));
                        break;
                    }
                }
            }
            return;
        }

        /* internal  */onOpt2BtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._info) 
            {
                var loc1=this._info.code;
                switch (loc1) 
                {
                    case DailyRule.GiftNovicePack1:
                    {
                        break;
                    }
                    case DailyRule.GiftNovicePack2:
                    {
                        BrowerUtil.getUrl(ParamsConst.instance.xskUrl);
                        break;
                    }
                    case DailyRule.GiftNovicePack3:
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GotoPay));
                        break;
                    }
                    case DailyRule.GiftPhonePack:
                    {
                        BrowerUtil.getUrl(ParamsConst.instance.phoneUrl);
                        break;
                    }
                    case DailyRule.GiftMall360Pack1: case DailyRule.GiftMall360Pack2:
                    {
                        BrowerUtil.getUrl(ParamsConst.instance.Mall360GiftUrl);
                        break;
                    }
                    case DailyRule.Gift91WanPack:
                    {
                        BrowerUtil.getUrl(ParamsConst.instance.Gift91Wan);
                        break;
                    }
                    case DailyRule.Gift360PetPack:
                    {
                        BrowerUtil.getUrl(ParamsConst.instance.Gift360PetUrl);
                        break;
                    }
                }
            }
            return;
        }

        /* internal  */onDailyGiftInfoResHandler(arg1: DataEvent): void
        {
            if (this._info) 
            {
                var loc1=this._info.code;
                switch (loc1) 
                {
                    case DailyRule.GiftNovicePack1:
                    {
                        break;
                    }
                    case DailyRule.GiftNovicePack2:
                    {
                        if (Cache.instance.daily.promotionCardUsed) 
                        {
                            this._optBtn1.enabled = false;
                        }
                        break;
                    }
                    case DailyRule.GiftNovicePack3:
                    {
                        if (Cache.instance.daily.firstPayPackUsed) 
                        {
                            this._optBtn1.enabled = false;
                        }
                        break;
                    }
                    case DailyRule.GiftPhonePack:
                    {
                        if (Cache.instance.daily.phoneGiftUsed) 
                        {
                            this._optBtn1.enabled = false;
                        }
                        break;
                    }
                }
            }
            return;
        }

        /* internal  */onAddToStage(arg1: Object /* flash.events.Event */): void
        {
            return;
        }

        protected onRemoveFromStage(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.removeEventListener(EventName.DailyGiftInfoRes, this.onDailyGiftInfoResHandler);
            this.closeTootipHandler(null);
            this.dispose();
            return;
        }

        /* internal  */onItemTextLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            var loc1=int(arg1.text);
            var loc2=this._info.items[loc1];
            if (!GiftItem._toolTip) 
            {
                GiftItem._toolTip = new Tooltip();
                GiftItem._closeBtn = ObjCreate.createGButton("", GiftItem._toolTip.width - 24, 4, 20, 18, null, "SmallCLoseBtn");
                GiftItem._spTooltipContainer.addChild(GiftItem._toolTip);
                GiftItem._spTooltipContainer.addChild(GiftItem._closeBtn);
            }
            GiftItem._point.x = mouseX;
            GiftItem._point.y = mouseY;
            GiftItem._point = localToGlobal(GiftItem._point);
            GiftItem._toolTip.data = loc2.getToolTipData();
            GiftItem._spTooltipContainer.x = GiftItem._point.x;
            GiftItem._spTooltipContainer.y = GiftItem._point.y;
            LayerManager.toolTipLayer.addChild(GiftItem._spTooltipContainer);
            GiftItem._closeBtn.x = GiftItem._toolTip.width - 24;
            GiftItem._closeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.closeTootipHandler);
            this.resetToolTipPosition();
            return;
        }

        /* internal  */resetToolTipPosition(): void
        {
            if (GiftItem._spTooltipContainer.x > Global.stage.stageWidth - GiftItem._spTooltipContainer.width - 6) 
            {
                GiftItem._spTooltipContainer.x = GiftItem._spTooltipContainer.x - GiftItem._spTooltipContainer.width - 6;
            }
            var loc1=1;
            GiftItem._spTooltipContainer.y = GiftItem._spTooltipContainer.y - GiftItem._spTooltipContainer.height - 6;
            if (GiftItem._spTooltipContainer.y < 0) 
            {
                GiftItem._spTooltipContainer.y = 0;
            }
            return;
        }

        /* internal  */closeTootipHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (GiftItem._spTooltipContainer && GiftItem._spTooltipContainer.parent) 
            {
                GiftItem._spTooltipContainer.parent.removeChild(GiftItem._spTooltipContainer);
            }
            return;
        }

        public updateData(arg1: GiftInfo): void
        {
            var loc4=0;
            var loc6=null;
            var loc8=0;
            this.dispose();
            this._info = arg1;
            var loc1=arg1.itemCodes[0];
            var loc2=ItemConfig.instance.getInfoByCode(loc1);
            this._name.htmlText = HTMLUtil.addColor(loc2.item.name, ColorConfig.instance.getItemColor(loc2.item.color).color);
            var loc3="";
            var loc5=arg1.items.length;
            while (loc4 < loc5) 
            {
                loc6 = arg1.items[loc4];
                loc3 = loc3 + ("<u><a href=\'event:" + loc4 + "\'>" + HTMLUtil.addColor(loc6.itemInfo.item.name + "×" + loc6.itemAmount, ColorConfig.instance.getItemColor(loc6.itemInfo.item.color).color) + "</a></u>");
                if (loc4 != (loc5 - 1)) 
                {
                    loc3 = loc3 + "<br>";
                }
                ++loc4;
            }
            this._itemTxt.htmlText = HTMLUtil.addColor(loc3, "#ffffff");
            this._itemTxt.textField.defaultTextFormat = new GTextFormat(FontUtil.songtiName, 12, 5635595, null, null, null, null, null, flash.text.TextFormatAlign.LEFT, null, null, null, 4);
            LoaderManager.instance.load(arg1.url, this.onIconLoadedHandler);
            this._itemDes.htmlText = HTMLUtil.addColor(this._info.des, "#b1efff");
            var loc7=true;
            var loc9=arg1.code;
            switch (loc9) 
            {
                case DailyRule.GiftNovicePack1:
                {
                    break;
                }
                case DailyRule.GiftNovicePack2:
                {
                    this._title.text = Language.getString(20501) + "：";
                    this._optBtn1.label = Language.getString(20502);
                    this._optBtn2.label = Language.getString(20503);
                    LoaderManager.instance.load("giftpack_2.png", this.onGiftTitleLoadedHandler);
                    break;
                }
                case DailyRule.GiftNovicePack3:
                {
                    if ((loc8 = Cache.instance.role.recharge) <= 0) 
                    {
                        loc7 = false;
                    }
                    this._title.text = Language.getString(20504) + "：";
                    this._optBtn1.label = Language.getString(20505);
                    this._optBtn2.label = Language.getString(20506);
                    Dispatcher.addEventListener(EventName.HavePay, this.onPlayerHavePayHandler);
                    LoaderManager.instance.load("giftpack_1.png", this.onGiftTitleLoadedHandler);
                    break;
                }
                case DailyRule.GiftPhonePack:
                {
                    this._title.text = Language.getString(25009) + "：";
                    this._optBtn1.label = Language.getString(25007);
                    this._optBtn2.label = Language.getString(25008);
                    LoaderManager.instance.load("giftpack_3.png", this.onGiftTitleLoadedHandler);
                    break;
                }
                case DailyRule.GiftMall360Pack1:
                {
                    this._title.text = Language.getString(25013) + "：";
                    this._optBtn1.label = Language.getString(25015);
                    this._optBtn2.label = Language.getString(25014);
                    LoaderManager.instance.load("giftpack_4.png", this.onGiftTitleLoadedHandler);
                    break;
                }
                case DailyRule.GiftMall360Pack2:
                {
                    this._title.text = Language.getString(25013) + "：";
                    this._optBtn1.label = Language.getString(25015);
                    this._optBtn2.label = Language.getString(25014);
                    LoaderManager.instance.load("giftpack_5.png", this.onGiftTitleLoadedHandler);
                    break;
                }
                case DailyRule.Gift91WanPack:
                {
                    this._title.text = Language.getString(25017) + "：";
                    this._optBtn1.label = Language.getString(25018);
                    this._optBtn2.label = Language.getString(25008);
                    LoaderManager.instance.load("giftpack_6.png", this.onGiftTitleLoadedHandler);
                    break;
                }
                case DailyRule.Gift360PetPack:
                {
                    this._title.text = Language.getString(25020) + "：";
                    this._optBtn1.label = Language.getString(25021);
                    this._optBtn2.label = Language.getString(25008);
                    LoaderManager.instance.load("giftpack_7.png", this.onGiftTitleLoadedHandler);
                    break;
                }
            }
            this._optBtn1.enabled = loc7;
            return;
        }

        public dispose(): void
        {
            Dispatcher.removeEventListener(EventName.HavePay, this.onPlayerHavePayHandler);
            return;
        }

        public /* override */ get width(): number
        {
            return 554;
        }

        public /* override */ get height(): number
        {
            return 200;
        }

        
        {
            GiftItem._spTooltipContainer = new Object /* flash.display.Sprite */();
            GiftItem._point = new Object /* flash.geom.Point */();
        }

        protected initUI(arg1: Boolean=false): void
        {
            this.initBg();
            if (arg1) 
            {
                return;
            }
            this._titleImg = new Object /* flash.display.Bitmap */();
            addChild(this._titleImg);
            this._itemBg = ResouceConst.getScaleBitmap(ImagesConst.PackItemBg);
            this._itemBg.width = 66;
            this._itemBg.height = 66;
            this._itemBg.x = 30;
            this._itemBg.y = 50;
            addChild(this._itemBg);
            this._itemIcon = new Object /* flash.display.Bitmap */();
            this._itemIcon.x = this._itemBg.x + 3;
            this._itemIcon.y = this._itemBg.y + 3;
            addChild(this._itemIcon);
            this._name = new Object /* flash.text.TextField */();
            this._name.filters = [FilterConst.nameGlowFilter];
            this._name.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._name.textColor = 11661311;
            this._name.selectable = false;
            this._name.width = 90;
            this._name.y = this._itemBg.y + this._itemBg.height;
            this._name.x = this._itemBg.x + this._itemBg.width / 2;
            addChild(this._name);
            this._title = new Object /* flash.text.TextField */();
            this._title.filters = [FilterConst.nameGlowFilter];
            this._title.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._title.textColor = 16646089;
            this._title.selectable = false;
            this._title.width = 120;
            this._title.y = this._itemBg.y;
            this._title.x = this._itemBg.x + this._itemBg.width + 5;
            this._title.text = Language.getString(20500) + "：";
            addChild(this._title);
            this._itemTxt = new GTextArea();
            this._itemTxt.textField.defaultTextFormat = new GTextFormat(FontUtil.songtiName, 12, 5635595, null, null, null, null, null, flash.text.TextFormatAlign.LEFT, null, null, null, 4);
            this._itemTxt.styleName = "GTextArea";
            this._itemTxt.wordWrap = true;
            this._itemTxt.editable = false;
            this._itemTxt.textField.selectable = false;
            this._itemTxt.width = 160;
            this._itemTxt.height = 100;
            this._itemTxt.horizontalScrollPolicy = ScrollPolicy.AUTO;
            this._itemTxt.verticalScrollPolicy = ScrollPolicy.AUTO;
            this._itemTxt.y = this._title.y;
            this._itemTxt.x = 195;
            this._itemTxt.text = "";
            this._itemTxt.textField.addEventListener(flash.events.TextEvent.LINK, this.onItemTextLinkHandler);
            addChild(this._itemTxt);
            this._optBtn1 = new GButton();
            this._optBtn1.styleName = "ButtonSpecial";
            this._optBtn1.setSize(100, 22);
            this._optBtn1.addEventListener(flash.events.MouseEvent.CLICK, this.onOpt1BtnClickHandler);
            this._optBtn1.x = 410;
            this._optBtn1.y = 60;
            this._optBtn1.label = Language.getString(20505);
            this._optBtn1.textField.filters = [FilterConst.nameGlowFilter];
            addChild(this._optBtn1);
            this._optBtn2 = new GButton();
            this._optBtn2.styleName = "ButtonSpecial";
            this._optBtn2.setSize(100, 22);
            this._optBtn2.addEventListener(flash.events.MouseEvent.CLICK, this.onOpt2BtnClickHandler);
            this._optBtn2.x = this._optBtn1.x;
            this._optBtn2.y = 100;
            this._optBtn2.label = Language.getString(20506);
            this._optBtn2.textField.filters = [FilterConst.nameGlowFilter];
            addChild(this._optBtn2);
            this._line = GlobalClass.getBitmap(ImagesConst.SplitLine);
            this._line.width = this.width - 40;
            this._line.y = 148;
            this._line.x = 20;
            addChild(this._line);
            this._itemDes = new Object /* flash.text.TextField */();
            var loc1=new GTextFormat(FontUtil.songtiName, 12, 16777215, null, null, null, null, null, flash.text.TextFormatAlign.LEFT, null, null, null, 4);
            this._itemDes.defaultTextFormat = loc1;
            this._itemDes.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._itemDes.textColor = 11661311;
            this._itemDes.selectable = false;
            this._itemDes.multiline = true;
            this._itemDes.wordWrap = true;
            this._itemDes.mouseEnabled = false;
            this._itemDes.width = this.width - 60;
            this._itemDes.height = 40;
            this._itemDes.y = this._line.y + 10;
            this._itemDes.x = 30;
            addChild(this._itemDes);
            return;
        }

        protected initBg(): void
        {
            this._bgImg = ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB);
            this._bgImg.width = this.width;
            this._bgImg.height = this.height;
            addChild(this._bgImg);
            this._titleBg = ResouceConst.getScaleBitmap(ImagesConst.RbListHeader);
            this._titleBg.width = this.width + 3;
            this._titleBg.y = -3;
            addChild(this._titleBg);
            return;
        }

        /* internal  */onGiftTitleLoadedHandler(arg1: ImageInfo): void
        {
            this._titleImg.bitmapData = arg1.bitmapData;
            this._titleImg.y = 5;
            this._titleImg.x = (this._bgImg.width - this._titleImg.bitmapData.width) / 2;
            return;
        }

        protected onPlayerHavePayHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            if (this._info.code == DailyRule.GiftNovicePack3 && this._optBtn1.enabled == false && loc1 > 0) 
            {
                this._optBtn1.enabled = true;
            }
            return;
        }

        /* internal  */onIconLoadedHandler(arg1: ImageInfo): void
        {
            if (this._itemIcon != null) 
            {
                this._itemIcon.bitmapData = arg1.bitmapData;
            }
            return;
        }

        protected /* var */_info: GiftInfo;

        protected /* var */_bgImg: ScaleBitmap;

        protected /* var */_titleBg: ScaleBitmap;

        protected /* var */_titleImg: Object /* flash.display.Bitmap */;

        protected /* var */_itemBg: Object /* flash.display.Bitmap */;

        protected /* var */_itemIcon: Object /* flash.display.Bitmap */;

        protected /* var */_name: Object /* flash.text.TextField */;

        protected /* var */_title: Object /* flash.text.TextField */;

        protected /* var */_itemTxt: GTextArea;

        protected /* var */_optBtn1: GButton;

        protected /* var */_optBtn2: GButton;

        protected /* var */_line: Object /* flash.display.Bitmap */;

        protected /* var */_itemDes: Object /* flash.text.TextField */;

        /* internal */ static /* var */_closeBtn: GButton;

        /* internal */ static /* var */_spTooltipContainer: Object /* flash.display.Sprite */;

        /* internal */ static /* var */_point: Object /* flash.geom.Point */;

        /* internal */ static /* var */_toolTip: Tooltip;
    }
